﻿#include <cmath>
#include <iostream>
#include <fstream>
#include "ppSline.h"
#include <nlohmann/json.hpp>
#include "project.h"
#include "Function.h"
using namespace std;

class FucntionA : public Function
{
public:
	double operator()(const double x) const {
		return 1 / (1 + 25 * x * x);
	}
	double diff(const double x) const {
		return -50 * x / pow(1 + 25 * x * x, 2);
	}
	double diff2(const double x) const {
		return 50 * (75 * x * x - 1) / pow(1 + 25 * x * x, 3);
	}

} functionA;

int main() {

	ifstream jsonFile("./json/A.json");
	nlohmann::json obj;
	jsonFile >> obj;
	double L = obj["L"];
	double R = obj["R"];
	double cond = obj["condition"];
	double ord = obj["order"];
	int N = obj["n"].size();
	cout << L << R << cond << ord << N << endl;

	for (int i = 0; i < 3; i++) {
		
		string fileName = "./Data/result_A_" + to_string(i + 1) + ".txt";
		ofstream outfile;
		outfile.open(fileName);
		for (int j = 0; j < obj["n"].size(); j++) {
			int N = obj["n"][j];
			PPspline<3> ppsline = PPspline<3>(functionA, L, R, N, i);
			for (int k = 0; k < 2000; k++) {
				double temp = L + 1.0 * k / 1999 * (R - L);
				outfile << temp << ' ' << ppsline.get_value(temp) << '\n';
			}
			
		}
		outfile.close();
	}


	
	



	
}

